n = input()
m = 0
count=0
if 999<int(n)<10000:
    for left in range(4):
        for right in range(left,4):
            num = int(n[left:right+1])
            for i in range(2,num//2):
                if num%i==0:
                    count=count+1
            if count==0:
                if m<num and num!=1:
                    m = num
    if m!=0:
        print(m)
    else:
        print("0")
else:
    print("0")

            
